/*************    (C) COPYRIGHT SUNSHINE SILICON  www.sunsili.com  *************
* File Name: app_led.h
* Description:
    Vioce device drivers
* Version    Date       Auther      Reversed History
  ----------------------------------------------------------------------------
  V1.0.0    2021-07-07  Lojam Fan  Fisrt Created 
  
  (C) Sunshine Silicon Corporation (www.sunsili.com)

*******************************************************************************/
#ifndef _APP_LED_H_
#define _APP_LED_H_

#include "gpio.h"
#include "pwm.h"
#include "ws2812.h"


#define LED_MOD_MAX 4
//#define WS_LED_LEN 78
//#define MAX_LED_LEN 78
//#define MAX_LED_LAYER 12
#define WS_LED_LEN 45
//#define MAX_LED_LEN 78
#define MAX_LED_LAYER 9
#define MAX_COL_LEN 45
#define LED3P_LEN 27

#define SW_CNT_MAX 3
#define MAX_CRL_ID 10
#define UNBIND_CRL_ID 11

#define PRE_10CM_LEDS   1
#define LED_FLASH_DUTY  100   //Prioed 1s 2*10*50
#define ADC_SMAPLE_DUTY 20  //Prioed 100ms 10*10
#define PWM_UPDATE_TIME 10  //Prioed PWM_UPDATE 
#define SHADE_TIME 100

#define MIN_ADC_VALID   5   //valid


typedef enum 
{
	MNC_TYPE = 0,  //monochrome
	CW_TYPE,     //Clod warm
	CLR_TYPE,    //Color
	RGB_TYPE,
    RGBW_TYPE,
    CLRFL_TYPE, //colorful
}led_type;

typedef enum 
{
	WIHTE_MODE = 0,  //monochrome	
	CLR_MODE,       //Color
    SCN_MODE,       //set light Scene
    MSC_MODE,       //Music 
}led_mode;

typedef enum 
{
	RGB = 0,  //monochrome	
	HSV,       //Color
}color_type_t;

typedef struct 
{
    bool sw;
    uint8_t gpio;
    uint8_t pwm_ch;
    uint16_t pwm_prd;
    uint16_t lum; //luminance lightness,
    uint16_t cw; 
    led_mode md;    
//    void *clr_param;
}led_t;


typedef struct 
{
    bool sw;
    uint8_t r_gpio;
    uint8_t r_pwm_ch;
    uint8_t g_gpio;
    uint8_t g_pwm_ch;
    uint8_t b_gpio;
    uint8_t b_pwm_ch;
    uint16_t pwm_prd;    
    uint16_t lum;       //luminance lightness,
    uint8_t flshSpd;    //Flash speed
    uint8_t funId;      //Scene funcation
    led_mode md;
    RGB_t   *rgbDat;
    uint8_t clrDatLen;
    uint8_t *datBuf;
}RGB_LED_t;

typedef struct 
{
    bool isDbCrl;
    bool sw;
    color_type_t clr_typ;
    uint8_t gpio_1p;
    uint8_t pwm_ch_1p;
    uint8_t gpio_1n;
    uint8_t pwm_ch_1n;
    uint8_t gpio_2p;
    uint8_t pwm_ch_2p;
    uint8_t gpio_2n;
    uint8_t pwm_ch_2n;
    uint8_t gpio_3p;
    uint8_t pwm_ch_3p;
    uint8_t gpio_3n;
    uint8_t pwm_ch_3n;
    uint16_t pwm_prd;    
    uint16_t lum; //luminance lightness,
    uint8_t flshSpd;    //Flash speed
    uint8_t funId;    //Scene funcation
    led_mode md;
    uint32_t timeOut;
    RGB_t   rgbDat[2];
    uint8_t clrDatLen;
    uint8_t *datBuf;
}RGB_LED3P_t;


typedef struct 
{
    uint16_t lum; //luminance lightness, 
    uint8_t flshSpd;    //Flash speed
    uint8_t funId;    //Scene funcation
    uint8_t div;
    uint8_t clrDatLen;
    uint8_t *datBuf;
}WS_LED_CTLR_DAT_t;

typedef struct 
{
    bool isDbCrl;
    uint16_t lum; //luminance lightness, 
    uint8_t flshSpd;    //Flash speed
    uint8_t funId;    //Scene funcation
    uint8_t div;
    uint8_t clrDatLen;
    uint8_t *datBuf;
}RGB_LED_CTLR_DAT_t;


typedef struct 
{
    bool sw;
	uint8_t gpio;    
    uint16_t lum; //luminance lightness,
    uint16_t cw;  
    uint8_t len;
    uint8_t flshSpd;    //Flash speed
    uint8_t funId;    //Scene funcation
    uint8_t div;
    uint32_t timeOut;
    uint8_t clrDatLen;
    led_mode md;    //Color Scene
    uint8_t *datBuf;
}WS_LED_t;


//extern WS_LED_t wsLed;
extern RGB_LED_t rgbLed;
extern RGB_LED3P_t rgbLed3p;
extern led_t led0;


//#define LED_1   0x11    //P11
//#define LED_2   0x12    //P12
//#define LED_3   0x13    //P13

#define ON      (1)
#define OFF     (0)


void app_led_init(void);
void app_led_timer_callback(void);
void app_adc_timer_callback(void);
void app_led_updata(led_t *pled);
uint32_t atoInt32(uint8_t *pData);


#endif

/*************    (C) COPYRIGHT SUNSHINE SILICON  www.sunsili.com  *************
********************         END OF FILE app_led.h           *******************/

